#ifndef IMAGE_FRAGMENT_H_
#define IMAGE_FRAGMENT_H_

#include "ZMLAlgorithm.h"
#include "../Scene/ZImageManager.h"

GLOBAL_NAMESPACE_BEGIN
NAMESPACE_MACHINE_LEARNING_BEGIN

class ImageFragmentParams
{
public:
    int u, v;   // left corner index w.r.p to ima_
    int w, h;   // fragment size
    std::string fragmentPath;

    ImageFragmentParams(int u0=0, int v0=0, int w0=0, int h0=0)
        : u(u0), v(v0), w(w0), h(h0) {}

    void setPath(const char* filePath);
    void output(std::ostream& out);
    void input(std::istream& in);
};

class ImageFragmentParamsIO
{
public:
    std::string imaFullPath;
    int id;
    std::string templateFullPath;
    int templateId;
    std::string maskFullPath;
    int maskId;
    ImageFragmentParams fragmentPara;
    int order;
};

class ImageFragment
{
public:
    ImageFragment(const char* imaPath="");
    ImageFragment(ImageSpace::Image* ima, const ImageFragmentParams& params);
    ImageFragment(const ImageFragmentParamsIO& input);

    bool isValid();
    void init(const ImageFragmentParams& params);
    void init(const ImageFragmentParamsIO& io);
    ImageSpace::Image* finalize();

    void output(std::ostream& out);

    const ImageFragmentParams* getFragmentParams() const;
    const ImageSpace::Image*   getImage() const;
    const ImageSpace::Image*   getTemplateImage() const;
    const ImageSpace::Image*   getMaskImage() const;

    void setOrder(int order);
    int  getOrder() const;

public:
    ImageFragmentParams params_;
    ImageSpace::Image* ima_;
    ImageSpace::Image* templateImg_;
    ImageSpace::Image* maskImg_;
    bool    bValid_;
    int     order_;

    bool bUseIoInitialize_;
    ImageFragmentParamsIO ioInput_;
};

NAMESPACE_MACHINE_LEARNING_END
GLOBAL_NAMESPACE_END

#endif//IMAGE_FRAGMENT_H_